package com.gxa.autoparts.portal.controller;


import com.gxa.autoparts.core.common.JsonResult;
import com.gxa.autoparts.core.pojo.Goods;
import com.gxa.autoparts.core.util.ThreadLocalUtil;
import com.gxa.autoparts.portal.service.UserBrowseRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/userBrowseRecordsController")
@Api(tags = "用户浏览记录")
public class UserBrowseRecordsController {

    @Autowired
    UserBrowseRecordsService userBrowseRecordsService=null;

    //基于数据变化大，采取redis做存储
    @PostMapping("/findRecords")
    @ApiOperation("查询用户浏览记录")
    public Map findAll() throws URISyntaxException {
        //Object o = ThreadLocalUtil.get();
        List<Goods> all = userBrowseRecordsService.findAll(1L);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(all);
        return jsonResult.getDataMap();

    }

    @PostMapping("/updateRecords")
    @ApiOperation("编辑浏览记录")
    public Map update(@RequestBody List<Long> list){
        userBrowseRecordsService.update(1L,list);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();

    }

    @PostMapping("/add")
    @ApiOperation("增加浏览记录")
    public Map add(@RequestParam("goodsId") Long goodsId){

        userBrowseRecordsService.add(1L,goodsId);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();

    }
}
